package storage.file;

import java.lang.reflect.Constructor;

import config.Config;


public class FileManagerFactory {

	private static AbstractFileManager fileManager = null;
	private static String packageName = FileManagerFactory.class.getPackage().getName();

	public static AbstractFileManager getFileManager() {
		if (fileManager == null) {
			String managerName = packageName + "." +
			Config.getString("fileManager", "FileManager");

			try{
				@SuppressWarnings("unchecked")
				Class<AbstractFileManager> managerClass = (Class<AbstractFileManager>) Class.forName(managerName);
				Constructor<AbstractFileManager> cons = managerClass.getConstructor(new Class[] {});
				fileManager = (AbstractFileManager) cons.newInstance(new Object[] {});
			}
			catch (Exception e){
				System.exit(0);
			}
		}

		return fileManager;
	}	

}
